<?php

require_once("Kzend/Bootstrap/Abstract.php");

// IncludePath
set_include_path(APPLICATION_PATH . '/controllers/Super' . PATH_SEPARATOR
    . APPLICATION_PATH . '/controllers/Helper' . PATH_SEPARATOR
    . APPLICATION_PATH . '/controllers/Plugin' . PATH_SEPARATOR
    . APPLICATION_PATH . '/controllers/Exception' . PATH_SEPARATOR
    . APPLICATION_PATH . '/models/Super' . PATH_SEPARATOR
    . APPLICATION_PATH . '/services' . PATH_SEPARATOR
    . APPLICATION_PATH . '/common' . PATH_SEPARATOR
    . get_include_path());

class Bootstrap extends Kzend_Bootstrap_Abstract
{

    public function __construct($application)
    {
	
        parent::__construct($application);
		
        Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/Helper', 'Action_Helper');
		
    }

    protected function _initView()
    {
	
        parent::_initView();
	}

    protected function _initDatabase()
    {
        parent::_initDatabase();
    }


    protected function _initAuth()
    {
	
        $this->bootstrap("frontController");
		
        $this->frontController->registerPlugin(new ControllerAuth());
		
    }
     protected function _initRouter()
        {
            $frontController = Zend_Controller_Front::getInstance();
            $router = $frontController->getRouter();
            if(isset($_SERVER['REQUEST_URI'])) {
                $url = strtolower($_SERVER['REQUEST_URI']);
                if (strpos($url,'/member/login-as-guest') !== false) {
                }elseif (strpos($url,'/member/index') !== false) {
                }elseif (strpos($url,'/member/logout') !== false) {
                }elseif (strpos($url,'/member/register') !== false) {
                }elseif (strpos($url,'/company/index') !== false) {
                }elseif (strpos($url,'/company/logout') !== false) {
                }elseif (strpos($url,'/company/login') !== false) {
                }elseif (strpos($url,'/company/forget-password') !== false) {
                }elseif (strpos($url,'/member/') !== false || strpos($url,'/company/') !== false) {
                    $route = new Zend_Controller_Router_Route(
                    ':module/:controller/:action/*',
                    array('module' => 'company')
                    ); 
                    $router->addRoute('default1', $route); 
                }
            }            
        } 

    protected function _initFrontController(){
           $front = Zend_Controller_Front::getInstance();       
           $front->addControllerDirectory(APPLICATION_PATH . "/controllers");
           
           $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routers.ini', 'thietlap');
          $router = new Zend_Controller_Router_Rewrite();
          
          $router = $router->addConfig($config, 'routes');
          
          $front->setRouter($router);
                          
           return $front;
        }
         
    /*
    protected function _initLogger()
    {
        // set Logger is null when run from cmd
        if (defined('ZFCLI_INVOKE')) {
            Zend_Registry::set("Kzend_Logger", new Zend_Log(new Zend_Log_Writer_Null()));
            return;
        }
        parent::_initLogger();
    }
    */
}
